#include "Goal_LeadGroup.h"
#include "Message.h"
#include "Message Dispatcher.h"
Goal_LeadGroup::Goal_LeadGroup(Character *owner, Group *group): Goal<Character>(owner, goal_lead_group),
																m_pGroup(group)
{
	;
}

void Goal_LeadGroup::Activate()
{
	m_iStatus = active;
	Dispatcher->DispatchMessage(-1, m_pOwner->ID(), MoveToLocation, &(m_pGroup->MoveGoal()));
}

int Goal_LeadGroup::Process()
{
	ActivateIfInactive();

	int dist = m_pOwner->Pos().DistanceSq(m_pGroup->MoveGoal());
	if(m_pOwner->Pos().DistanceSq(m_pGroup->MoveGoal()) < 3600)
	{
		m_iStatus = completed;
	}

	return m_iStatus;
}

void Goal_LeadGroup::Terminate()
{
	Log->AddMessage("Calling Terminate LeadGroup()", blue);
}

void Goal_LeadGroup::DeferLeadership()
{
	m_pGroup->Remove(this->m_pOwner);
	m_pGroup->SetLeader();
	m_pGroup->Move(m_pGroup->MoveGoal());

	Log->AddMessage("Exiting DeferLeadership()");
	m_iStatus = failed;
}

bool Goal_LeadGroup::HandleMessage(const Message& msg)
{
	return false;
}